/**
 * 溶解氧电极
 */
Electrode = Widget.extend({
	runningAction:null,
	runningAction1:null,
	runningAction2:null,
	runningAction3:null,
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_ELECTRODE_ALL);
	},
	init:function(){
		this.body = new Button(this, 10, TAG_ELECTRODE, "#electrode.png", this.callback,this);
		this.body.setRotation(-90);
		//拿电极左手
		var left_1=new Button(this,10,TAG_LEFT_1,"#left_1.png",this.callback,this);
		left_1.setPosition(this.width*0.5,this.height*0.5);
		left_1.setVisible(false);
		var left_2=new Button(left_1,10,TAG_LEFT_2,"#left_2.png",this.callback,this);
		left_2.setPosition(left_1.width*0.5,left_1.height*0.5);
		var left_3=new Button(left_1,10,TAG_LEFT_3,"#left_3.png",this.callback,this);
		left_3.setPosition(left_1.width*0.5,left_1.height*0.5);
		//拿蒸馏水瓶右手
		var right1=new Button(this,10,TAG_RIGHT1,"#right1.png",this.callback,this);
		right1.setPosition(this.width*0.5+500,this.height*0.5);
		right1.setVisible(false);
		var right2=new Button(right1,10,TAG_RIGHT2,"#right2.png",this.callback,this);
		right2.setPosition(right1.width*0.5,right1.height*0.5);
		var right3=new Button(right1,10,TAG_RIGHT3,"#right3.png",this.callback,this);
		right3.setPosition(right1.width*0.5,right1.height*0.5);
		//拿保护套右手
		var body_1=new Button(this,11,TAG_ELECTRODE_1,"#electrode_action/body_1.png",this.callback,this);
		body_1.setPosition(this.width+65,this.height-5);
		body_1.setVisible(false);
		//保护套
		var top1=new Button(this,11,TAG_TOP1,"#top1.png",this.callback,this);
		top1.setPosition(this.width+200,this.height-5);
		top1.setVisible(false);
		//拿紧帽右手
		var body_2=new Button(this,11,TAG_ELECTRODE_2,"#electrode_action1/body_2.png",this.callback,this);
		body_2.setPosition(this.width+55,this.height-5);
		body_2.setVisible(false);
		//紧帽
		var tight=new Button(this,14,TAG_TIGHT,"#Tight.png",this.callback,this);
		tight.setPosition(this.width+280,this.height-5);
		tight.setVisible(false);
		//压环（带衫环）
		var pressure=new Button(this,13,TAG_PRESSURE,"#Pressure.png",this.callback,this);
		pressure.setPosition(this.width+350,this.height-5);
		pressure.setVisible(false);
		//托座
		var bracket=new Button(this,11,TAG_BRACKET,"#Bracket.png",this.callback,this);
		bracket.setPosition(this.width+420,this.height-5);
		bracket.setVisible(false);
		//薄膜
		var film=new Button(this,12,TAG_FILM_1,"#film.png",this.callback,this);
		film.setPosition(this.width+420,this.height);
		film.setVisible(false);
		//衫环
		var shirt=new Button(this,12,TAG_SHIRT,"#Shirt.png",this.callback,this);
		shirt.setPosition(this.width+490,this.height-5);
		shirt.setVisible(false);
		//拿仪器右手
		var right_11=new Button(this,12,TAG_RIGHT11,"#right_11.png",this.callback,this);
		right_11.setPosition(this.width+360,this.height-25);
		right_11.setVisible(false);
		var right_12=new Button(right_11,12,TAG_RIGHT12,"#right_12.png",this.callback,this);
		right_12.setPosition(right_11.width*0.5,right_11.height*0.5);
		var right_13=new Button(right_11,12,TAG_RIGHT13,"#right_13.png",this.callback,this);
		right_13.setPosition(right_11.width*0.5,right_11.height*0.5);
		
		var pressure_action=new cc.Sprite("#pressure_action/action1.png");
		pressure_action.setPosition(this.width+500,this.height);
		pressure_action.setScale(0.6);
		pressure_action.setVisible(false);
		this.addChild(pressure_action,11,TAG_PRESSURE_ACTION);
		this.initAction();
		this.initAction1();
		this.initAction2();
	},
	initAction:function(){
		var animFrames=[];
		for(var i=1;i<7;i++){
			var str="electrode_action/action"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.3);
		this.runningAction=cc.repeat(cc.animate(animation),1);
		this.runningAction.retain();
	},
	initAction1:function(){
		var animFrames=[];
		for(var i=1;i<7;i++){
			var str="electrode_action1/action"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.3) 
		this.runningAction1=cc.repeat(cc.animate(animation),1);
		this.runningAction1.retain();
	},
	initAction2:function(){
		var animFrames=[];
		for(var i=1;i<6;i++){
			var str="pressure_action/action"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation=new cc.Animation(animFrames,0.3) 
		this.runningAction2=cc.repeat(cc.animate(animation),1);
		this.runningAction2.retain();
	},
	show:function(){
		var pressure_show=new Button(this,15,TAG_PRESSURE_SHOW,"#Pressure_2.png",this.callback,this);
		pressure_show.setPosition(this.width+490,this.height+50);
		pressure_show.setOpacity(0);
		var fadein=cc.fadeIn(1);
		var fadeout=cc.fadeOut(1);
		pressure_show.runAction(cc.sequence(fadein,cc.delayTime(1),fadeout));
	},
	show1:function(){
		var tight3=new Button(this,15,TAG_TIGHT2,"#Tight_2.png",this.callback,this);
		tight3.setPosition(this.width+280,this.height+80);
		tight3.setScale(1.3);
		tight3.setOpacity(0);
		var fadein=cc.fadeIn(1);
		var fadeout=cc.fadeOut(1);
		tight3.runAction(cc.sequence(fadein,cc.delayTime(1),fadeout));
	},
	callback:function(p){
		var func=cc.callFunc(function(){
			gg.flow.next();
		},this);
		var action=gg.flow.flow.action;
		var body=this.getChildByTag(TAG_ELECTRODE);
		var body_1=this.getChildByTag(TAG_ELECTRODE_1);
		var body_2=this.getChildByTag(TAG_ELECTRODE_2);
		var pressure_action=this.getChildByTag(TAG_PRESSURE_ACTION);
		var top1=this.getChildByTag(TAG_TOP1);
		var tight=this.getChildByTag(TAG_TIGHT);
		var pressure=this.getChildByTag(TAG_PRESSURE);
		var bracket=this.getChildByTag(TAG_BRACKET);
		var shirt=this.getChildByTag(TAG_SHIRT);
		var film=this.getChildByTag(TAG_FILM_1);
		var left_1=this.getChildByTag(TAG_LEFT_1);
		var left_2=left_1.getChildByTag(TAG_LEFT_2);
		var left_3=left_1.getChildByTag(TAG_LEFT_3);
		var right_11=this.getChildByTag(TAG_RIGHT11);
		var Instrument=ll.run.getChildByTag(TAG_MP_INSTRUMENT);
		var main=Instrument.getChildByTag(TAG_MAIN);
		var instrument1=main.getChildByTag(TAG_INSTRUMENT2);
		var num=instrument1.getChildByTag(TAG_NUM);
		var button=main.getChildByTag(TAG_BUTTON);
		switch(p.getTag()){
		case TAG_ELECTRODE:
			if(action==ACTION_DO1){
				body.runAction(cc.sequence(this.runningAction,cc.callFunc(function() {
					body.setSpriteFrame("electrode_action/body1.png");
					body.setPosition(cc.p(this.width-10,this.height+32));
					body_1.setVisible(true);
					body_1.runAction(cc.sequence(cc.spawn(cc.moveBy(1,cc.p(250, 0)),cc.rotateBy(1,-90)),cc.callFunc(function() {
						body_1.setVisible(false);
						top1.setVisible(true);
					},this)));
				},this),cc.delayTime(1),func));
			}else if(action==ACTION_DO2){
				body.runAction(cc.sequence(cc.callFunc(function() {
					body.setPosition(cc.p(this.width,this.height));
				}, this),this.runningAction1,cc.callFunc(function() {
					body.setSpriteFrame("electrode_action1/body2.png");
					body_2.setVisible(true);
				},this),cc.spawn(cc.callFunc(function() {
					body.runAction(cc.sequence(cc.rotateBy(1,90),cc.callFunc(function() {
						body.setSpriteFrame("electrode_action/electrode_2.png");
					},this)));
				},this),
				cc.callFunc(function() {
					body_2.runAction(cc.sequence(cc.spawn(cc.moveBy(0.5,cc.p(350, 0)),cc.rotateBy(0.5,-90)),
						cc.callFunc(function() {
						body_2.setVisible(false);
						tight.setVisible(true);
						},this)));
				},this)),func));
			}
			break;
		case TAG_TIGHT:
			var rotate=cc.rotateBy(1,-180);
			var ber=cc.bezierBy(1, [cc.p(-20,50),cc.p(-230,180),cc.p(-243, 85)]);
			if(action==ACTION_DO1){
				p.runAction(cc.sequence(cc.callFunc(function() {
					pressure.setVisible(true);
				},this),func));
			}else if(action==ACTION_DO2){
				p.setVisible(false);
				right_11.setVisible(true);
				right_11.runAction(cc.sequence(ber,cc.callFunc(function() {
					right_11.setVisible(false);
					left_2.setSpriteFrame("left_21.png");
				},this),func));
			}
			break;
		case TAG_PRESSURE:
			if(action==ACTION_DO1){
				pressure_action.setVisible(true);
				pressure_action.runAction(cc.sequence(this.runningAction2,cc.callFunc(function() {
					pressure_action.setVisible(false);
					bracket.setVisible(true);
				},this),func));
			}else if(action==ACTION_DO2){
				var ber=cc.bezierBy(1, [cc.p(10,20),cc.p(50, 35),cc.p(71,0)]);
				p.runAction(cc.sequence(ber,cc.callFunc(function() {
					shirt.setVisible(false);
					film.setVisible(false);
					bracket.setVisible(false);
				},this),func));
			}else if(action==ACTION_DO3){
				p.runAction(cc.sequence(cc.sequence(cc.callFunc(function() {
					pressure_action.setVisible(true);
					pressure_action.runAction(cc.sequence(this.runningAction2.reverse(),cc.callFunc(function() {
						pressure_action.setVisible(false);
					},this)));
				},this)),cc.delayTime(2),func));
			}else if(action==ACTION_DO4){
				var rotate=cc.rotateBy(1,180);
				var rotate1=cc.rotateBy(1,180);
				var ber=cc.bezierBy(1,[cc.p(-10,30),cc.p(-35, 50),cc.p(-71, 5)]);
				p.runAction(cc.sequence(cc.spawn(ber,cc.callFunc(function() {
					tight.runAction(cc.sequence(rotate,cc.callFunc(function() {
						p.setVisible(false);
						tight.setSpriteFrame("Tight_1.png");
						tight.setRotation(0);
					},this)));
				},this)),cc.callFunc(function() {
					this.show1();
				},this),cc.delayTime(2),func));
			}
			break;
		case TAG_BRACKET:
			var ber=cc.bezierBy(1, [cc.p(-10,20),cc.p(-50, 35),cc.p(-71,0)]);
			var rotate=cc.rotateBy(1,-180);
			var rotate1=cc.rotateBy(1,180);
			if(action==ACTION_DO1){
				p.runAction(cc.sequence(cc.callFunc(function() {
					shirt.setVisible(true);
				},this),func));
			}else if(action==ACTION_DO2){
				p.runAction(cc.sequence(cc.spawn(cc.sequence(cc.spawn(ber,rotate),cc.callFunc(function() {
					p.setSpriteFrame("Bracket_1.png");
					p.setRotation(0);
					p.setLocalZOrder(15);
				},this)),cc.callFunc(function() {
					pressure.runAction(cc.sequence(rotate1,cc.callFunc(function() {
						p.setVisible(false);
						pressure.setSpriteFrame("Pressure1.png");
						pressure.setRotation(0);
					}, this)));
				},this)),func));
			}
			break;
		case TAG_SHIRT:
			var ber=cc.bezierBy(1, [cc.p(-10, 25),cc.p(-35, 35),cc.p(-64, 5)]);
				p.runAction(cc.sequence(cc.callFunc(function() {
					var film1=ll.run.getChildByTag(TAG_FILM);
					film1.setVisible(false);
					film.setVisible(true);
				},this),ber,cc.callFunc(function() {
					bracket.setSpriteFrame("Bracket1.png");
					film.setVisible(false);
					p.setVisible(false);
					this.show();
				},this),cc.delayTime(3),func));
			break;
		case TAG_LEFT_1:
			var rotate=cc.rotateBy(1,95);
			if(action==ACTION_DO1){
				p.runAction(cc.sequence(rotate,cc.callFunc(function() {
					var water=new cc.Sprite("#water.png");
					water.setPosition(this.width+100,-this.height-50);
					this.addChild(water);
					water.runAction(cc.sequence(cc.moveBy(1,cc.p(0, -100)),cc.fadeOut(1)));
				},this),rotate.reverse(),func));
			}else if(action==ACTION_DO2){
				var Instrument=ll.run.getChildByTag(TAG_MP_INSTRUMENT);
				var main=Instrument.getChildByTag(TAG_MAIN);
				var instrument1=main.getChildByTag(TAG_INSTRUMENT2);
				var instrument=main.getChildByTag(TAG_INSTRUMENT1);
				var line=main.getChildByTag(TAG_LINE);
				instrument.setVisible(false);
				instrument1.setVisible(true);
				line.setVisible(true);
				var move=cc.moveBy(1,cc.p(0, -53));
				var button=ll.run.getChildByTag(TAG_MP_INSTRUMENT).main.getChildByTag(TAG_BUTTON);
				line.runAction(cc.sequence(move,cc.callFunc(function() {
					left_2.setSpriteFrame("left_4.png");
					left_2.setPosition(cc.p(left_1.width*0.5,left_1.height*0.6))
				},this),cc.delayTime(1),cc.callFunc(function() {
					line.setSpriteFrame("line1.png");
					line.setPosition(Instrument.main.width*0.55, Instrument.main.height*0.83);
					button.setVisible(true);
					left_1.setSpriteFrame("left_4.png");
					left_2.setVisible(false);
					left_3.setVisible(false);
				},this),func));
			}else if(action==ACTION_DO3){
				left_1.runAction(cc.sequence(cc.callFunc(function() {
					left_1.setSpriteFrame("right_33.png");
					left_1.runAction(cc.sequence(cc.moveTo(1, cc.p(this.width+350, this.height+100)),
							cc.moveTo(1,cc.p(this.width+350, this.height+80)),cc.callFunc(function() {
									var animFrames=[];
									for(var i=17;i>0;i--){
										var str="num_action/num"+i+".png";
										var frame=cc.spriteFrameCache.getSpriteFrame(str);
										animFrames.push(frame);
									}
									var animation=new cc.Animation(animFrames,0.3) 
									this.runningAction3=cc.repeat(cc.animate(animation),1);
									this.runningAction3.retain();
									num.runAction(this.runningAction3);
							},this),cc.delayTime(6),cc.callFunc(function(){
						ll.run.clock.doing();
						button.setVisible(true);
					},this),cc.delayTime(2),cc.callFunc(function() {
						ll.run.clock.stop();
					},this),func));
				},this)));
			}
			break;
		default:
			break;
		}
	}
});